<?php

namespace App\Http\Controllers\App;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class StoreController extends Controller
{
    public function get_stores(){
        return $this->handle($this->getService('Store')->stores());
    }

    // 获取店铺信息
    public function get_store_info($id){
        $data = $this->getService('Store')->getStoreInfoAndRate($id);
        $storeClass = $this->getService('StoreClass',true)->select('id','class_name','class_id')->where('store_id',$id)->first();
        $class_name = [];
        $class_id = [];
        if(!empty($storeClass)){
            $classIdList = json_decode($storeClass['class_id'],true);
            foreach($classIdList as $k=>$v){
                $class_id[] = $classIdList[$k][2];
                $class_name[] = $this->getService('GoodsClass',true)->select('name')->where('id',$classIdList[$k][2])->first()['name'];
            }
        }
        $data['data']['store_classes'] = $class_name;
        $data['data']['store_classes_id'] = $class_id;
        $data['data']['sale_list'] = $this->getService('Goods')->sortGoods($id)['data'];
        return $this->handle($data);
        // }
    }



}
